﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter7.Section2
{
    public class Example11
    {
        public Example11()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double, double[]> ff
                = new V.Function.ToLastType<double, double[]>(func);
            V.Path c = new V.Path(ff);
            c.ParameterFrom = 0.0;
            c.ParameterTo = 4.0;
            V.Function.ToLastType<double[], double[]> fff
                = new V.Function.ToLastType<double[], double[]>(f);
            V.VectorField F = new V.VectorField(fff);
            V.LineIntegral obj = new V.LineIntegral(F, c);
            obj.Compute();
            result += obj.Result.ToString() + "\r\n";

            double res = 1.0 / 2.0;
            result += res.ToString() + "\r\n";
        }
        private double[] func(double t)
        {
            double[] x = new double[2];
            if (0.0 <= t & t <= 1.0) 
            { 
                x[0] = t;
                x[1] = 0.0;
            }
            else if (1.0 <= t & t <= 2.0)
            {
                x[0] = 1.0;
                x[1] = t - 1.0;
            }
            else if (2.0 <= t & t <= 3.0)
            {
                x[0] = 3.0 - t;
                x[1] = 1.0;
            }
            else
            {
                x[0] = 0.0;
                x[1] = 4.0 - t;
            }
            return x;
        }
        private double[] f(double[] x)
        {
            double[] r = new double[2];
            r[0] = x[0]*x[0];
            r[1] = x[0]*x[1];
            return r;
        }
    }
}
/*
0.499999934618134
0.5
*/

